//
//  XxgkMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-5-23.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "XxgkMainViewController.h"
#import "QzfwjViewController.h"
#import "BgswjViewController.h"
#import "CwhyViewController.h"
#import "QthyViewController.h"
#import "GzhyViewController.h"
#import "RsrmViewController.h"
#import "XxgknbViewController.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) 
#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))

@implementation XxgkMainViewController

@synthesize Btn_back;
@synthesize imageView1;
@synthesize EGOview;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [self AddImageView];
    [self addBtns:[self AddScrollView]];
}

-(void)AddImageView{
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    [imageView setImage:[UIImage imageNamed:@"bgImg_xxgk.png"]];
    [self.view addSubview:imageView];
}

-(UIScrollView *)AddScrollView{

    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 160+diff/1.7, 320, 411)]autorelease];
    //[scrollView setBackgroundColor:[UIColor grayColor]];
    [scrollView setContentSize:CGSizeMake(320, 520)];
    [self.view addSubview:scrollView];
    return scrollView;
}

-(void)addBtns:(UIScrollView *)ScrollView{
    [self addWenJianBtns:ScrollView];
    [self addHuiYiBtns:ScrollView];
    [self addQiTaBtns:ScrollView];
}


-(void)addWenJianBtns:(UIScrollView *)ScrollView{
    [self addLabelToScrollView:ScrollView :0 :@"文件"];
    [self addBtnToScrollView:ScrollView :30 :@"btn_qzfwj" :1];
    [self addBtnToScrollView:ScrollView :64 :@"btn_bgswj" :2];
}

-(void)addHuiYiBtns:(UIScrollView *)ScrollView{
    [self addLabelToScrollView:ScrollView :104 :@"会议"];
    [self addBtnToScrollView:ScrollView :134 :@"btn_cwhy" :3];
    [self addBtnToScrollView:ScrollView :168 :@"btn_qthy" :4];
    [self addBtnToScrollView:ScrollView :202 :@"btn_gzhy" :5];
}

-(void)addQiTaBtns:(UIScrollView *)ScrollView{
    [self addLabelToScrollView:ScrollView :246 :@"其他"];
    [self addBtnToScrollView:ScrollView :276 :@"btn_rsrm" :6];
    [self addBtnToScrollView:ScrollView :310 :@"btn_xxgknb" :7];
}

-(void)addLabelToScrollView:(UIScrollView *)ScrollView :(int)y_zuobiao :(NSString *)text{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(25, y_zuobiao, 320, 30)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:16.5f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor darkGrayColor]];
    [label setText:text];
    [ScrollView addSubview:label];
}

-(void)addBtnToScrollView:(UIScrollView *)ScrollView :(int) y_zuobiao :(NSString *)img :(int)flag{
    CGRect frame=CGRectMake(25, y_zuobiao, 270, 34);
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    btn.frame = frame;
    switch (flag) {
        case 1:
            [btn addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button11Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 2:
            [btn addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button22Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 3:
            [btn addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button33Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 4:
            [btn addTarget:self action:@selector(Button4Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button44Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 5:
            [btn addTarget:self action:@selector(Button5Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button55Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 6:
            [btn addTarget:self action:@selector(Button6Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button66Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 7:
            [btn addTarget:self action:@selector(Button7Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button77Clicked) forControlEvents:UIControlEventTouchDown];
            break;
            
    }
    
    [ScrollView addSubview:btn];
}
-(void)Button11Clicked{
    downFlag=1;
}

-(void)Button22Clicked{
    downFlag=2;
}

-(void)Button33Clicked{
    downFlag=3;
}

-(void)Button44Clicked{
    downFlag=4;
}

-(void)Button55Clicked{
    downFlag=5;
}

-(void)Button66Clicked{
    downFlag=6;
}

-(void)Button77Clicked{
    downFlag=7;
}

-(void)Button1Clicked{
    if (downFlag==1) {
        QzfwjViewController *qzfwj=[[QzfwjViewController alloc]init];
        EGOview=qzfwj.view;
        [self.view addSubview:qzfwj.view];
        [self AddImageView:1];
    }
}

-(void)Button2Clicked{
    if (downFlag==2) {
        BgswjViewController *bgswj=[[BgswjViewController alloc]init];
        EGOview=bgswj.view;
        [self.view addSubview:bgswj.view];
        [self AddImageView:2];
    }

}

-(void)Button3Clicked{
    if (downFlag==3) {
        CwhyViewController *cwhy=[[CwhyViewController alloc]init];
        EGOview=cwhy.view;
        [self.view addSubview:cwhy.view];
        [self AddImageView:3];
    }

}

-(void)Button4Clicked{
    if (downFlag==4) {
        QthyViewController *qthy=[[QthyViewController alloc]init];
        EGOview=qthy.view;
        [self.view addSubview:qthy.view];
        [self AddImageView:4];
    }

}

-(void)Button5Clicked{
    if (downFlag==5) {
        GzhyViewController *gzhy=[[GzhyViewController alloc]init];
        EGOview=gzhy.view;
        [self.view addSubview:gzhy.view];
        [self AddImageView:5];
    }

}

-(void)Button6Clicked{
    if (downFlag==6) {
        RsrmViewController *rsrm=[[RsrmViewController alloc]init];
        EGOview=rsrm.view;
        [self.view addSubview:rsrm.view];
        [self AddImageView:6];
    }

}

-(void)Button7Clicked{
    if (downFlag==7) {
        XxgknbViewController *xxgknb=[[XxgknbViewController alloc]init];
        EGOview=xxgknb.view;
        [self.view addSubview:xxgknb.view];
        [self AddImageView:7];
    }

}


-(void) AddImageView:(int)flag{
    UIImageView *imageView=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 87+diff/1.7, 320, 30)]autorelease];
    [imageView setBackgroundColor:[UIColor blueColor]];
    imageView1=imageView;
    [self.view addSubview:imageView];
    [self AddLabel:imageView :flag];
    [self AddBtn_back];
}

-(void) AddLabel:(UIImageView *)imageView :(int)flag{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(0, 1, 320, 28)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor blueColor]];
    [label setTextColor:[UIColor whiteColor]];
    switch (flag) {
        case 1:{
            [label setText:@"区政府文件"];
            break;}
        case 2:{
            [label setText:@"办公室文件"];
            break;}
        case 3:{
            [label setText:@"常务会议"];
            break;}
        case 4:{
            [label setText:@"全体会议"];
            break;}
        case 5:{
            [label setText:@"工作会议"];
            break;}
        case 6:{
            [label setText:@"人事任免"];
            break;}
        case 7:{
            [label setText:@"信息公开年报"];
            break;}
            
    }
    [label setTextAlignment:NSTextAlignmentCenter];
    [imageView addSubview:label];
}

-(void)AddBtn_back{
    CGRect frame=CGRectMake(21, 87+diff/1.7, 72, 29);
    UIButton *btn_back=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn_back setTag:50];
    [btn_back setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    btn_back.frame=frame;
    [btn_back addTarget:self action:@selector(Btn_back_Clicked) forControlEvents:UIControlEventTouchUpInside];
    [[self view]addSubview:btn_back];
    Btn_back=btn_back;
}

-(void)Btn_back_Clicked{

    [EGOview removeFromSuperview];
    [Btn_back removeFromSuperview];
    [imageView1 removeFromSuperview];

}
@end























